<template>
  <rt-list
    ref="moresearchList"
    :table-name="tableName"
    :columns="columns"
    :title="title"
    :controller-name="controllerName"
    :search-param="searchList"
    :operations="operations"
    :input-search-param="quickSearch"
    :custom-operations="customOperations"
    :custom-button-operation="customButtonOperations"
    :customize-action="customizeAction"
    :hide-title="false"
    :reset="reset"
    search-placeholder="输入评论或者文章标题进行搜索"
  >
    <rt-form slot="search">
      <rt-row :gutter="15">
        <rt-col :span="12">
          <rt-form-item label="评论时间">
            <el-date-picker
              v-model="timeValue"
              style="width: 500px"
              range-separator="至"
              start-placeholder="请选择"
              end-placeholder="请选择"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </rt-form-item>
        </rt-col>
      </rt-row>
    </rt-form>
  </rt-list>
</template>

<script>
import RtList from '../../components/custome/rtList.vue';
import RtCol from 'vue-xpc/src/components/col/rtCol';
export default {
  name: 'CommentList',
  components: {
    RtCol,
    RtList
  },
  data() {
    return {
      timeValue: [],
      controllerName: 'bbs/postcommentlog',
      tableName: 'bbs_post_comment_log',
      title: '评论审核',
      queryValue: '',
      operations: ['search', 'advanced-search', 'customdelete'],
      columns: [
        {
          prop: 'text',
          label: '评论内容',
          sortable: true,
          type: 'customizeAction',
          autoCol: true,
          actionId: 'bbs_post_comment_logid'
        },
        {
          prop: 'object_name',
          label: '文章标题',
          sortable: true,
          autoCol: true
        },
        {
          prop: 'createdon',
          sortable: true,
          label: '评论时间',
          format: 'YYYY-MM-DD HH:mm:ss',
          width: 220
        }
      ],
      // tableParam: {
      //   startTime: '',
      //   endTime: ''
      // },
      quickSearch: ['object_name', 'text'],
      customOperations: [
        {
          operate: 'customdelete',
          operateName: '删除',
          iconName: 'rt-base-delete',
          type: 'primary'
        }
      ],
      customButtonOperations: {
        customdelete: ids => {
          if (ids.length === 0) {
            rt.showErrorToast('请至少选择一条记录');
          } else {
            this.$confirm(
              `您一共选择了${ids.length}条记录，确认要删除吗？`,
              '提示',
              {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }
            )
              .then(() => {
                rt.post(`api/bbs/postcommentlog/muldelcomment`, ids)
                  .then(res => {
                    rt.showSuccessToast('删除成功');
                    this.$refs.moresearchList.refreshTable();
                  })
                  .catch(error => {
                    rt.showErrorToast(error);
                  });
              })
              .catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                });
              });
          }
        }
      }
    };
  },
  computed: {
    searchList() {
      const searchList = [];
      // if (!rt.isNil(this.tableParam.startTime)) {
      //   searchList.push({ key: 'createdon', value: this.tableParam.startTime });
      // }
      // if (!rt.isNil(this.tableParam.endTime)) {
      //   searchList.push({
      //     key: 'createdon',
      //     value: this.tableParam.endTime
      //   });
      // }
      if (!rt.isNilOrEmptyArray(this.timeValue)) {
        searchList.push({
          operator: 'between',
          key: 'createdon',
          type: 1,
          value: this.timeValue
        });
      }

      return searchList;
    }
  },
  created() {},
  methods: {
    // getTimeValue() {
    //   if (this.timeValue) {
    //     this.tableParam.startTime = this.timeValue[0];
    //     this.tableParam.endTime = this.timeValue[1];
    //   } else {
    //     this.tableParam.startTime = '';
    //     this.tableParam.endTime = '';
    //   }
    // },
    //重置
    reset() {
      this.timeValue = [];
    },
    customizeAction(row, actionId) {
      this.$router.push({
        name: 'commentdetail',
        params: { id: row[actionId] }
      });
    }
  }
};
</script>

<style scoped></style>
